package cn.zn.modules.member.controller;

import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zn.modules.member.entity.MemberIndexEntity;
import cn.zn.modules.member.service.MemberIndexService;
import cn.zn.framework.common.utils.PageInUtils;
import cn.zn.framework.common.utils.PageUtils;
import cn.zn.framework.common.utils.R;


/**
 * 会员等级指标
用于计算会员等级的项目
 *
 * @author zn
 * @email zhunahao@qq.com
 * @date 2020-12-14 15:30:05
 */
@RestController
@RequestMapping("member/memberindex")
public class MemberIndexController {
    @Autowired
    private MemberIndexService memberIndexService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("member:memberindex:list")
    public R list(PageInUtils<MemberIndexEntity> pageIn) {

        PageUtils pageUtils = memberIndexService.queryPage(pageIn);

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("member:memberindex:info")
    public R info(@PathVariable("id") Long id) {
            MemberIndexEntity memberIndex = memberIndexService.getById(id);

        return R.ok().put("memberIndex", memberIndex);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("member:memberindex:save")
    public R save(@RequestBody MemberIndexEntity memberIndex) {
            memberIndexService.save(memberIndex);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member:memberindex:update")
    public R update(@RequestBody MemberIndexEntity memberIndex) {
            memberIndexService.updateById(memberIndex);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("member:memberindex:delete")
    public R delete(@RequestBody Long[] ids) {
            memberIndexService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
